from django.core.paginator import Paginator


def pageRange(page, queryset):
    page_size = 15
    paginator = Paginator(queryset, page_size)
    total_pages = paginator.num_pages
    half_visible = 5  # 显示当前页码前后的页码数
    start_page = max(page - half_visible, 1)
    end_page = min(start_page + 10 - 1, total_pages)
    page_range = range(start_page, end_page + 1)
    page_size = 15
    start = (page - 1) * page_size
    end = page * page_size
    if page == 1:
        Pre, Next = 1, page + 1
    elif page == total_pages:
        Pre, Next = page - 1, total_pages
    else:
        Pre, Next = page - 1, page + 1
    return page_range, start, end, Pre, Next
